<?php

namespace App\Http\Controllers\Home;

use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use EasyWeChat\Foundation\Application;

//生成二维码
class QrcodeController extends Controller
{   
    public $qrcode;
    public function __construct(Application $app) {
        $this->qrcode = $app->qrcode;
    }
    public function qrcode(){
        $qrcode = $this->qrcode;
        $result = $this->qrcode->temporary(56,3600); //生成临时的二维码
        //$result = $this->qrcode->forever(56);    //生成永久二维码
        //$result = $this->qrcode->forever('foo'); //生成永久二维码
        //return $result;
        return view('home.qrcode',  compact('result','qrcode')); //此处的qrcode必须返回，否则前台无法显示此二维码
    }
    
    //获获取二维码内容
    public function qrcodeUrl($ticket){
        $url = $this->qrcode->url($ticket);
        $content = file_get_contents($url); // 得到二进制图片内容
        file_put_contents(public_path(). '/images/code.jpg', $content); // 写入文件
    }
}
